
(function($) {  // ENSURE PLUGIN WORKS IN CONFLICT MODE

// **********************
// **********************
// MULTI LINK BANNER
// **********************
$.fn.MAD_MultiLinkBanner = function() {
	
	return this.each(function() {

		var $this = $(this);
		
		var clickArea = ($this.width() / $this.children('a').length);
		$this.children('a').css({width:clickArea});
	});
};
// END OF MULTILINK BANNER


// **********************
// **********************
// IMAGE FADER - BANNER ROTATOR
// **********************
$.fn.MAD_Slideshow = function(o) {
	o = $.extend({
        paging: true,
		transition: 'fade',
        speed: 6000
    }, o || {});

	return this.each(function() {

		var $this = $(this);  // Declare as local variable

		// CREATE PAGING
		var slideCount = $this.children('div').length;
		
//		var clickArea = ($this.width() / $this.children('div').find('a').length);
//		$this.children('div').find('a').css({width:clickArea});
				
		if (o.paging) {
			var pagingLinks = '';
			for (i = 1; i <= slideCount; i++) {
				pagingLinks += '<a href="#" title="" rel="' + (i) + '">' + i + '</a>';
			}
			$this.parent().append('<div class="paging">' + pagingLinks + '</div>');
			$this.parent().find(".paging a:first").addClass("active");
		
			var active = $this.parent().find(".paging a:first");
			var play;
			
			// FADE TIMER
			function fadeImage(clear){
				if (clear) {
					$this.children('div').stop(true,true).fadeOut();
				}
				$this.children('div:eq(' + ((active.attr("rel"))-1) + ')').stop(true,true).fadeIn();

				play = setInterval(function() {
					$this.children('div:eq(' + ((active.attr("rel"))-1) + ')').stop(true,true).fadeOut();
					active = $this.parent().find(".paging a.active").removeClass('active').next();
					if ( active.length === 0) { // IF AT END RETURN TO FIRST
						active = $this.parent().find(".paging a:first");
					}
					active.addClass('active');
					$this.children('div:eq(' + ((active.attr("rel"))-1) + ')').stop(true,true).fadeIn();
				}, o.speed);

			};
					
			// CATCH CLICK EVENT
			$this.parent().find(".paging a").click(function() {
				active = $(this); //Activate the clicked paging
				$this.parent().find(".paging a").removeClass('active');
				$(this).addClass('active')
				clearInterval(play); //Stop the rotation
				fadeImage(true);
				return false;
			});
			
			// CATCH HOVER
			$this.children('div').hover(function() {
				clearInterval(play); //Stop the rotation
			}, function() {
				fadeImage(false);
			});	
		
		fadeImage(true);
		}
		else { // IF PAGING IS OFF SIMPLY LOOP THROUGH
			if (slideCount > 1) {
				$this.children('div:first-child').show()
				setInterval(function(){
				  $this.children('div:first-child').fadeOut()
					 .next('div').fadeIn()
					 .end().appendTo($this);
				}, o.speed);
			}
			else {
				$this.children('div').show();	
			}
		}
	});
};
// END OF FADER PLUGIN





})(jQuery); 

// LIGHTBOX